#!/usr/bin/env python
# Based on a hook from dzone.com
# Source: https://dzone.com/articles/an-in-depth-look-at-git-hooks
#
# Deletes all .pyc files every time a new branch is checked out.
#
# Requirements: 
#   * Python 2/3
#
# To enable this hook, rename this file to "post-checkout".

import sys, os, re
from subprocess import check_output

# Collect the parameters
previous_head = sys.argv[1]
new_head = sys.argv[2]
is_branch_checkout = sys.argv[3]
if is_branch_checkout == "0":
print "post-checkout: This is a file checkout. Nothing to do."
sys.exit(0)
print "post-checkout: Deleting all '.pyc' files in working directory"
for root, dirs, files in os.walk('.'):
for filename in files:
ext = os.path.splitext(filename)[1]
if ext == '.pyc':
os.unlink(os.path.join(root, filename))